package com.yfore.jfinal.pdf.plugin;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.nio.charset.Charset;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by farmer on 16/8/31.
 *
 * @author 1256810099@qq.com
 */
public class MockHttpServletResponse implements InvocationHandler {

	// private PrintWriter printWriter =  new MockPrintWriter(new StringWriter());

    private MockServletOutputStream outputStream = new MockServletOutputStream();
	
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        // if ("getWriter".equals(method.getName())) {
        //     String str = StringUtils.toEncodedString(outputStream.toByteArray(), Charset.forName("UTF-8"));
        //     printWriter.print( str );
        //     return printWriter;
        // }
        if ("getOutputStream".equals(method.getName())) {
            return outputStream;
        }
        return null;
    }
    
}